module("luci.controller.Ditel_ACU.ACU_Antenna", package.seeall) --定义一个lua模块
--local log = require "luci.log"

local sqlite3 = require("lsqlite3")
--数据库名
local db_name = "/etc/config/log_app.db"
--数据表名
local table_name = "ant_modem"

function sleep(n)
    os.execute("sleep "..n)
end
function index()
    entry({"admin", "ACU_Antenna"}, firstchild(), translate("Antenna Configuration"), 106)

        entry({"admin", "ACU_Antenna", "Overview"}, template("ACU_Overview/overview"), translate("Antenna Overview"), 107)
            --获取天线温湿度信息
            entry({"admin", "ACU_Antenna", "getTemperature"}, call("run_getTemperature") , nil, nil).leaf = true
            --获取STM32程序版本信息
            entry({"admin", "ACU_Antenna", "getAcuVersion"}, call("run_getAcuVersion") , nil, nil).leaf = true
            --获取天线程序版本、型号信息
            entry({"admin", "ACU_Antenna", "getSysinfo"}, call("run_getSysinfo") , nil, nil).leaf = true

        entry({"admin", "ACU_Antenna", "AntennaStatus"}, template("ACU_AntennaInfo/antennaInfo"), translate("Antenna Status"), 108)
            --获取天线状态信息
            entry({"admin", "ACU_Antenna", "getAntennaStatus"}, call("run_getAntennaStatus") , nil, nil).leaf = true	
			
        entry({"admin", "ACU_Antenna", "SatelliteInfo"}, template("ACU_SatelliteInfo/satelliteInfo"), translate("Satellite Status"), 109)
            --获取卫星信息
            entry({"admin", "ACU_Antenna", "getSatelliteInfo"}, call("run_getSatelliteInfo") , nil, nil).leaf = true
            --获取卫星列表
            entry({"admin", "ACU_Antenna", "getSatelliteList"}, call("run_getSatelliteList") , nil, nil).leaf = true
            --设置卫星列表
            entry({"admin", "ACU_Antenna", "setSatelliteList"}, call("run_setSatelliteList") , nil, nil).leaf = true
            --切换卫星
            entry({"admin", "ACU_Antenna", "switchSatellite"}, call("run_switchSatellite") , nil, nil).leaf = true	
            --同步卫星列表
            entry({"admin", "ACU_Antenna", "asySatellite"}, call("run_asySatellite") , nil, nil).leaf = true	
     
			
        entry({"admin", "ACU_Antenna", "Ins"}, template("ACU_Ins/ins"), translate("Antenna Ins"), 110)
            --获取天线惯导信息
            entry({"admin", "ACU_Antenna", "getIns"}, call("run_getIns") , nil, nil).leaf = true
			
        entry({"admin", "ACU_Antenna", "Sub"}, template("ACU_Sub/sub"), translate("Antenna Sub"), 111)
            --发送设置副面参数指令
            entry({"admin", "ACU_Antenna", "getSub"}, call("run_getSub") , nil, nil).leaf = true
            --发送获取副面参数指令
            entry({"admin", "ACU_Antenna", "setSub"}, call("run_setSub") , nil, nil).leaf = true
			
        entry({"admin", "ACU_Antenna", "AntennaAlarm"}, template("ACU_AntennaAlarm/antennaAlarm"), translate("Antenna Alarm"), 112)
            --获取天线告警信息
            entry({"admin", "ACU_Antenna", "getAntennaAlarm"}, call("run_getAntennaAlarm") , nil, nil).leaf = true			
			
        entry({"admin", "ACU_Antenna", "Calibration"}, template("ACU_Calibration/calibration"), translate("Calibrate Antenna"), 113).index = true
            --发送天线检测指令
            entry({"admin", "ACU_Antenna", "calibration"}, call("run_calibration") , nil, nil).leaf = true
            --发送天线校准指令
            entry({"admin", "ACU_Antenna", "setAdjustSet"}, call("run_setAdjustSet") , nil, nil).leaf = true
            --获取天线测试信息
            entry({"admin", "ACU_Antenna", "getTestInfo"}, call("run_getTestInfo") , nil, nil).leaf = true
            --持续获取天线校准返回信息
            entry({"admin", "ACU_Antenna", "getCalibrationReturn"}, call("run_getCalibrationReturn") , nil, nil).leaf = true
			--清空测试日志文件
            entry({"admin", "ACU_Antenna", "clearCalibrationReturn"}, call("run_clearCalibrationReturn") , nil, nil).leaf = true
            
        entry({"admin", "ACU_Antenna", "Manual"}, template("ACU_Manual/manual"), translate("Manual Antenna"), 114)
            --发送进入、退出手动模式指令
            entry({"admin", "ACU_Antenna", "manual"}, call("run_manual") , nil, nil).leaf = true
            --发送手动控制指令
            entry({"admin", "ACU_Antenna", "manualItems"}, call("run_manualItems") , nil, nil).leaf = true

        entry({"admin", "ACU_Antenna", "AntennaEcharts"}, template("ACU_Block/block"), translate("Antenna Block Test"), 115)
            --刷新遮挡测试数据
            entry({"admin", "ACU_Antenna", "refreshBlock"}, call("run_refreshBlock") , nil, nil).leaf = true
            --清空遮挡测试数据
            entry({"admin", "ACU_Antenna", "clearBlock"}, call("run_clearBlock") , nil, nil).leaf = true
            --获取航向角和方位角零位值
            entry({"admin", "ACU_Antenna", "getHeadingAzi"}, call("run_getHeadingAzi") , nil, nil).leaf = true
            --设置航向角和方位角零位值
            entry({"admin", "ACU_Antenna", "setHeadingAzi"}, call("run_setHeadingAzi") , nil, nil).leaf = true

		entry({"admin", "ACU_Antenna", "Restart"}, template("ACU_AntennaRestart/restart"), translate("Restart Antenna"), 116)
			--重启天线指令
            entry({"admin", "ACU_Antenna", "restart"}, call("run_restart") , nil, nil).leaf = true
            
        entry({"admin", "ACU_Antenna", "Log"}, template("ACU_Log/log"), translate("Antenna Log"), 117)
			--天线日志
            entry({"admin", "ACU_Antenna", "getLog"}, call("run_getLog") , nil, nil).leaf = true
            entry({"admin", "ACU_Antenna", "clearAntLog"}, call("run_clearAntLog") , nil, nil).leaf = true
end

function check(filename, t)
    local str = ""
    if nixio.fs.access(filename)
    then
        for i=1,t,1 do
            sleep(1)
            str = nixio.fs.readfile(filename, 128)
            if(string.len(str) > 10)
            then
                luci.http.write(str)
                return 0;
            end
        end
        luci.http.write("Error:"..filename.." is empty\n")	
    else
        luci.http.write("Error: open "..filename.." failed\n")
    end

    return -1;
end
--检查返回数据是否成功，并将数据或告警发送给WEB
function chreck_return(filename)

    local str = ""
    if nixio.fs.access(filename)
    then 
        str = nixio.fs.readfile(filename, 128)

        --判断文件中是否有数据
        if(string.len(str) < 10)
        then
            --提示告警
            str = "Error:"..filename.." is empty\n"
        end
    else
        --提示告警
        str = "Error: open "..filename.." failed\n"
    end
    --将数据发送给WEB
    luci.http.write(str)
    --发送数据完成后，清空文件
    nixio.fs.writefile(filename, "")
end
--发送进入、退出测试模式
function run_calibration()
    if nixio.fs.access("/etc/config/WEB/Calibration/TestInput")
    then 
        local step = luci.http.formvalue("step")
        local str = ""
        if (step == '9')
        then
            str = "$GCCMD,ENTER TEST SAT*FF\r\n"
        elseif (step == '10')
        then
            str = "$GCCMD,EXIT TEST SAT*FF\r\n"
        else
            str = "$GCCMD,SET ANT TEST,"..step.."*FF\r\n"
        end
        nixio.fs.writefile("/etc/config/WEB/Calibration/TestInput", str)
		
        check("/etc/config/WEB/Calibration/TestOutput", 5)
    else
        luci.http.write("Error: open /etc/config/WEB/Calibration/TestInput failed\n")
    end
end
--持续获取校准模式返回信息
function run_getCalibrationReturn()
    if nixio.fs.access("/etc/config/WEB/Calibration/TestLogFile")
    then 
        --读取返回的信息内容并且返回在文件
        local str = nixio.fs.readfile("/etc/config/WEB/Calibration/TestLogFile", 2048)
        --判断文件中是否有数据
        if(string.len(str) > 5)
        then
            --发送读取到的数据到WEB
            luci.http.write(str)
        end
    end
end
--清空校准模式返回信息
function run_clearCalibrationReturn()
    if nixio.fs.access("/etc/config/WEB/Calibration/TestLogFile")
    then 
		luci.http.write("")
    end
end
--天线校准指令
function run_setAdjustSet()
    if nixio.fs.access("/etc/config/WEB/Adjust/AdjustInput")
    then 
        local para1 = luci.http.formvalue("para1")
        local para2 = luci.http.formvalue("para2")
        local para3 = luci.http.formvalue("para3")
        local para4 = luci.http.formvalue("para4")
        local para5 = luci.http.formvalue("para5")
        local para6 = luci.http.formvalue("para6")
        
        local str = string.format("$GCCMD,SET ADJUST ANT,%s,%s,%s,%s,%s,%s,0,0*FF\r\n",
            para1, para2, para3, para4, para5, para6)
        nixio.fs.writefile("/etc/config/WEB/Adjust/AdjustInput", str)

        check("/etc/config/WEB/Adjust/AdjustOutput", 5)
    else
        luci.http.write("Error: open /etc/config/WEB/Adjust/AdjustInput failed\n")
    end
end
--获取天线测试信息
function run_getTestInfo()
    if nixio.fs.access("/etc/config/WEB/Test/TestInfoInput")
    then
        --local step = luci.http.formvalue("step")
        --将指令写入到文件中
        nixio.fs.writefile("/etc/config/WEB/Test/TestInfoInput", "$GCCMD,GET TEST DATA*FF\r\n")

        check("/etc/config/WEB/Test/TestInfoOutput", 5)
    else
        luci.http.write("Error: open /etc/config/WEB/Test/TestInfoInput failed\n")
    end
end
--进发送进入、退出手动模式
function run_manual()
    if nixio.fs.access("/etc/config/WEB/Manual/ManualInput")
    then 
        local step = luci.http.formvalue("step")
        local str = ""
        if (step == '10')
        then
            str = "$GCCMD,ENTER MANUAL SEARCH SAT*FF\r\n"
        elseif (step == '11')
        then
            str = "$GCCMD,EXIT MANUAL SEARCH SAT*FF\r\n"
        end

        nixio.fs.writefile("/etc/config/WEB/Manual/ManualInput", str)
		
        check("/etc/config/WEB/Manual/ManualOutput", 5)
		
    else
        luci.http.write("Error: open /etc/config/WEB/Manual/ManualInput failed\n")
    end
end
--手动控制天线运动指令
function run_manualItems()
    if nixio.fs.access("/etc/config/WEB/Manual/ManualItemsInput")
    then 
        local para1 = luci.http.formvalue("para1")
        local para2 = luci.http.formvalue("para2")
        local para3 = luci.http.formvalue("para3")
        
        local str = string.format("$GCCMD,MANUAL SEARCH SET,%s,%s,%s*FF\r\n",
            para1, para2, para3)

        nixio.fs.writefile("/etc/config/WEB/Manual/ManualItemsInput", str)
		
        check("/etc/config/WEB/Manual/ManualItemsOutput", 5)
    else
        luci.http.write("Error: open /etc/config/WEB/Manual/ManualItemsInput failed\n")
    end
end
--获取副面参数
function run_getSub()
    if nixio.fs.access("/etc/config/WEB/Sub/GetSubInput")
    then
        --local step = luci.http.formvalue("step")
        --将指令写入到文件中
        nixio.fs.writefile("/etc/config/WEB/Sub/GetSubInput", "$GCCMD,GET SUB DATA*FF\r\n")
		
        check("/etc/config/WEB/Sub/GetSubOutput", 5)

    else
        luci.http.write("Error: open /etc/config/WEB/Sub/GetSubInput failed\n")
    end
end
--设置副面参数指令
function run_setSub()
    if nixio.fs.access("/etc/config/WEB/Sub/SetSubInput")
    then 
        local para1 = luci.http.formvalue("para1")
        local para2 = luci.http.formvalue("para2")
        local para3 = luci.http.formvalue("para3")
        local para4 = luci.http.formvalue("para4")
        --确保相位偏差百分比和相位数正确
        if((tonumber(para3) ~= nil) and (tonumber(para4) ~= nil))
        then
            local str = string.format("$GCCMD,SET SUB REF,%s,%s,%s,%s*FF\r\n",
            para1, para2, para3, para4)
            nixio.fs.writefile("/etc/config/WEB/Sub/SetSubInput", str)
			
            check("/etc/config/WEB/Sub/SetSubOutput", 5)
        else
            luci.http.write("Error: please get sub data first\n")
        end
    else
            luci.http.write("Error: open /etc/config/WEB/Sub/SetSubInput failed\n")
    end
end
--获取天线状态信息
function run_getAntennaStatus()
    if nixio.fs.access("/etc/config/WEB/AntennaStatus/GetStatusInput")
    then
        --local step = luci.http.formvalue("step")
        --将指令写入到文件中
        nixio.fs.writefile("/etc/config/WEB/AntennaStatus/GetStatusInput", "$GCCMD,GET ANT DIR*FF\r\n")
		
        check("/etc/config/WEB/AntennaStatus/GetStatusOutput", 5)
    else
        luci.http.write("Error: open /etc/config/WEB/AntennaStatus/GetStatusInput failed\n")
    end
end
--获取卫星状态信息
function run_getSatelliteInfo()
    if nixio.fs.access("/etc/config/WEB/SatelliteInfo/GetSatelliteInfoInput")
    then
        --local step = luci.http.formvalue("step")
        --将指令写入到文件中
        nixio.fs.writefile("/etc/config/WEB/SatelliteInfo/GetSatelliteInfoInput", "$GCCMD,GET SAT DATA*FF\r\n")

        check("/etc/config/WEB/SatelliteInfo/GetSatelliteInfoOutput", 5)
    else
        luci.http.write("Error: open /etc/config/WEB/SatelliteInfo/GetSatelliteInfoInput failed\n")
    end
end
--获取对应的卫星参数
function run_getSatelliteList()
    if nixio.fs.access("/etc/config/WEB/SatelliteInfo/SatelliteList")
    then
        local para1 = luci.http.formvalue("para1")
        local str = nixio.fs.readfile("/etc/config/WEB/SatelliteInfo/SatelliteList", 1024)
        for word in string.gmatch(str, "%b{}")
        do
            if string.match(word, "%d+") == para1
            then
                luci.http.write(word)
            end
        end
    else
        luci.http.write("Error: open /etc/config/WEB/SatelliteInfo/SatelliteList failed\n")
    end
end
--保存卫星列表
function run_setSatelliteList()
    if nixio.fs.access("/etc/config/WEB/SatelliteInfo/SatelliteList")
    then
        local para1 = luci.http.formvalue("para1")
        local rep1 = luci.http.formvalue("str")

        local str = nixio.fs.readfile("/etc/config/WEB/SatelliteInfo/SatelliteList", 1024)
        local temp = {}
        for word in string.gmatch(str, "%b{}")
        do
            if string.match(word, "%d+") == para1
            then
                temp = word
            end
        end
        local str1 = string.gsub(str, temp, rep1)
        nixio.fs.writefile("/etc/config/WEB/SatelliteInfo/SatelliteList", str1)
        luci.http.write("Success\n")
    else
        luci.http.write("Error: open /etc/config/WEB/SatelliteInfo/SatelliteList failed\n")
    end
end
--切换卫星
function run_switchSatellite()
    if nixio.fs.access("/etc/config/WEB/SatelliteInfo/SwitchSatelliteInput")
    then 
        local para1 = luci.http.formvalue("para1")
        local para2 = luci.http.formvalue("para2")
        local para3 = luci.http.formvalue("para3")
        local para4 = luci.http.formvalue("para4")
        local para5 = luci.http.formvalue("para5")
        local para6 = luci.http.formvalue("para6")
        local para7 = luci.http.formvalue("para7")
        local para8 = luci.http.formvalue("para8")
        local para9 = luci.http.formvalue("para9")
        local para10 = luci.http.formvalue("para10")
        local para11 = luci.http.formvalue("para11")
        local para12 = luci.http.formvalue("para12")
        local para13 = luci.http.formvalue("para13")
        local para14 = luci.http.formvalue("para14")
        local para15 = luci.http.formvalue("para15")
        
        local str = string.format("$GCCMD,AUTO SEARCH WEB,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s*FF\r\n",
            para4, para5, para10, para6, para7, para11, para12, para13, para14, para8, para15, para1, para9, para2, para3)
        nixio.fs.writefile("/etc/config/WEB/SatelliteInfo/SwitchSatelliteOutput", "")
        nixio.fs.writefile("/etc/config/WEB/SatelliteInfo/SwitchSatelliteInput", str)
		
        check("/etc/config/WEB/SatelliteInfo/SwitchSatelliteOutput", 5)

    else
        luci.http.write("Error: open /etc/config/WEB/SatelliteInfo/SwitchSatelliteInput failed\n")
    end
end

--同步卫星列表
function run_asySatellite()

    local s = luci.http.formvalue("para")

    if(s == "download")
    then
        --同步列表到ACU
        --1. 打开卫星列表
        if nixio.fs.access("/etc/config/WEB/SatelliteInfo/SatelliteList")
        then
            --2. 读取数据
            local str = nixio.fs.readfile("/etc/config/WEB/SatelliteInfo/SatelliteList", 1024)
            --3. 打包数据
            local str1 = string.format("$GCCMD,DOWNLOAD SAT LIST,%s*FF\r\n", str);
            --4. 写入数据
            nixio.fs.writefile("/etc/config/WEB/SatelliteInfo/UpdateSatListInput", str1)
            --5. 查看返回信息
            check("/etc/config/WEB/SatelliteInfo/UpdateSatListOutput", 5)
        else
            luci.http.write("Error: open /etc/config/WEB/SatelliteInfo/SatelliteList failed\n")
        end
    elseif(s == "upload")
    then
        --从ACU同步卫星列表
        --1. 写入指令
        nixio.fs.writefile("/etc/config/WEB/SatelliteInfo/UpdateSatListInput", "$GCCMD,UPLOAD SAT LIST*FF\r\n")
        --2. 延时1s
        sleep(1)
        --3. 读取返回数据
        local str = nixio.fs.readfile("/etc/config/WEB/SatelliteInfo/UpdateSatListOutput", 1024)
        --4. 提取需要的数据
        local str1 = string.sub(str, string.len("$GCCMD,UPLOAD SAT LIST,") + 1, -(string.len("*FF\r\n") + 1));
        --5. 写入到文件
        nixio.fs.writefile("/etc/config/WEB/SatelliteInfo/SatelliteList", str1)
        luci.http.write("upload success.")
    else
        luci.http.write("Error: cmd "..s.."wrong")
    end

end
--获取天线告警信息
function run_getAntennaAlarm()
    if nixio.fs.access("/etc/config/WEB/Alarm/AntennaAlarmInput")
    then
        --将指令写入到文件中
        nixio.fs.writefile("/etc/config/WEB/Alarm/AntennaAlarmInput", "$GCCMD,GET ANT ALM*FF\r\n")
        check("/etc/config/WEB/Alarm/AntennaAlarmOutput", 5)
    else
        luci.http.write("Error: open /etc/config/WEB/Alarm/AntennaAlarmInput failed\n")
    end
end
--获取天线温湿度信息
function run_getTemperature()
    if nixio.fs.access("/etc/config/WEB/Temperature/TemperatureInput")
    then
        --将指令写入到文件中
        nixio.fs.writefile("/etc/config/WEB/Temperature/TemperatureInput", "$GCCMD,GET TEMP DATA*FF\r\n")

        check("/etc/config/WEB/Temperature/TemperatureOutput", 5)
    else
        luci.http.write("Error: open /etc/config/WEB/Temperature/TemperatureInput failed\n")
    end
end
--获取惯导信息
function run_getIns()
    if nixio.fs.access("/etc/config/WEB/Ins/InsInput")
    then
        --将指令写入到文件中
        nixio.fs.writefile("/etc/config/WEB/Ins/InsInput", "$GCCMD,GET INS DATA*FF\r\n")

        check("/etc/config/WEB/Ins/InsOutput", 5)
    else
        luci.http.write("Error: open /etc/config/WEB/Ins/InsInput failed\n")
    end
end
--获取ACU版本
function run_getAcuVersion()
    if nixio.fs.access("/etc/config/WEB/AcuSystem/AcuSystemInput")
    then
        --将指令写入到文件中
        nixio.fs.writefile("/etc/config/WEB/AcuSystem/AcuSystemInput", "$GCCMD,GET ACU VERSION*FF\r\n")

        check("/etc/config/WEB/AcuSystem/AcuSystemOutput", 5)
    else
        luci.http.write("Error: open /etc/config/WEB/AcuSystem/AcuSystemInput failed\n")
    end
end
--获取天线版本
function run_getSysinfo()
    if nixio.fs.access("/etc/config/WEB/AntennaSystem/AntennaSystemInput")
    then
        --将指令写入到文件中
        nixio.fs.writefile("/etc/config/WEB/AntennaSystem/AntennaSystemInput", "$GCCMD,GET SYSINFO*FF\r\n")

        check("/etc/config/WEB/AntennaSystem/AntennaSystemOutput", 5)
    else
        luci.http.write("Error: open /etc/config/WEB/AntennaSystem/AntennaSystemInput failed\n")
    end
end

--重启天线指令
function run_restart()
    if nixio.fs.access("/etc/config/WEB/AntennaReboot/AntennaRebootInput")
    then
        --将指令写入到文件中
        nixio.fs.writefile("/etc/config/WEB/AntennaReboot/AntennaRebootInput", "$GCCMD,SYSTEM RESET*FF\r\n")

        check("/etc/config/WEB/AntennaReboot/AntennaRebootOutput", 5)
    else
        luci.http.write("Error: open /etc/config/WEB/AntennaReboot/AntennaRebootInput failed\n")
    end
end

--获取航向角和SNR数据
function run_refreshBlock()
    local filename = "/etc/config/save_file"
    if nixio.fs.access(filename)
    then
        local str = nixio.fs.readfile(filename, 2048) --最多需要1500字节左右
        luci.http.write(str)
    end
end

--清空航线角和SNR数据
function run_clearBlock()
    local filename = "/etc/config/save_file"
    if nixio.fs.access(filename)
    then
        nixio.fs.writefile(filename, "");
        luci.http.write("clear success.")
    else
        luci.http.write("Error: open" ..filename.."failed\n");
    end
end

--获取航向角和方位角零位值
function run_getHeadingAzi()
    local filename = "/etc/config/head_azi_zero_file"
    if nixio.fs.access(filename)
    then
        local str = nixio.fs.readfile(filename, 128)
        luci.http.write(str)
    else
        luci.http.write("Error: open" ..filename.."failed\n");
    end
end

--设置航向角和方位角零位值
function run_setHeadingAzi()
    local filename = "/etc/config/head_azi_zero_file"
    if nixio.fs.access(filename)
    then
        local heading = luci.http.formvalue("para1")
        local cur_azimuth = luci.http.formvalue("para2")
        local pre_azimuth = luci.http.formvalue("para3")
        local str = string.format("$GCCMD,HEAD AZIMUTH ZERO,%s,%s,%s*FF\r\n", heading, cur_azimuth, pre_azimuth)
        nixio.fs.writefile(filename, str)
    else
        luci.http.write("Error: open" .. filename .."failed\n");
    end
end

--获取日志的内容
function run_getLog()

    --1. 判断请求的页码和请求页码的大小
    local page_num = luci.http.formvalue("pgn")
    local page_size = luci.http.formvalue("pgs")
    --local page_num = 1
    --local page_size = 30

    if page_num == nil and page_size == nil  
    then
        --默认值
        page_num = 0
        page_size = 30
    end

    --2. 根据页码和页码大小打包SQL语句
    local sql_str = string.format("select * from ant_modem order by time desc limit %d offset %d", page_size, page_num * page_size)

    --print("sql_str: "..sql_str)
    --3. 打开数据库
    local db = sqlite3.open(db_name)
    local str_all = ""
    local str_one = ""
    if db then
        --4. 查询数据
        for row in db:nrows(sql_str) do
            --4.1 获取数据库内容
            --print(row.TIME, row.LEVEL, row.EVENT)
            --4.2 保存数据,将表中的数据封装成字符串 {"time,level,event":"time,level,event";}
            str_one = string.format("%s,%s,%s;",row.TIME, row.LEVEL, row.EVENT)
            --print("str one:"..str_one)
            str_all = str_all..str_one
        end
        --5. 关闭数据库
        db:close()
        --print("str_all: ", str_all)
        --print("str_all_size:", string.len(str_all))
        --6. 将数据发送给前端
        luci.http.write(str_all)
    else
        luci.http.write("open db falied")
    end
end

--清空日志
function run_clearAntLog()
    --1. 打开数据库
    local db = sqlite3.open(db_name)
    if db then
        --2. 清空表
        --5. 关闭数据库
        db:exec("delete from ANT_MODEM")
        db:close()
        luci.http.write("Clear OK")
    else
        luci.http.write("open db falied")
    end 
end